﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;
using BSCMFF.Core;

namespace BSCMFF.Web.Pages.Reporting
{
    public partial class EmployeesPKPI : MultiLanguagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FillGridPKPIsScore(28);
        }

        private void FillGridPKPIsScore(int evalID)
        {
            BSCEntities context = new BSCEntities();

            var data = (from epk in context.Evaluation_PKPIs
                        join ee in context.Evaluation_Evaluator_Employee on epk.EEE_FK equals ee.ID
                        where ee.Evaluation_FK == evalID
                        group epk by new { ee.Employee_FK } into g
                        join u in context.Users on g.Key.Employee_FK equals u.ID
                        orderby u.ID
                        select new
                        {
                            fullname = u.Firstname + " " + u.Lastname,
                            pkpi = g.Sum(epk => (double)epk.Weight * epk.Score) / 10,
                            //count = g.Select(x => x.ID).Count()

                        });

            RadGrid1.DataSource = data;
            RadGrid1.DataBind();
        }
    }
}